import { IVacancyAlarmRes } from '@/types/device'
import axios, { ResponseData } from 'yuxin-base/src/utils/axios'
export function getLockLicense(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/lock_auth/list',
		data,
		method: 'POST'
	})
}

// 门禁授权列表
export function getAccessAuthorize(data: object): Promise<ResponseData> {
	return axios.request({
		url: 'device/access/authorize/list',
		method: 'POST',
		data
	})
}

export const trafficWarning = (data: object): Promise<ResponseData> => {
	return axios.request({
		url: '/device/device/traffic_warnings',
		method: 'POST',
		data
	})
}
export const queryDeviceOnlineStatus = (data: object): Promise<ResponseData> => {
	return axios.request({
		url: '/device/device/queryDeviceOnlineStatus',
		method: 'POST',
		data
	})
}
export const accessWarningLog = (data: object): Promise<ResponseData> => {
	return axios.request({
		url: '/device/access/user/warning_log/page',
		method: 'POST',
		data
	})
}

// 门禁列表
export function getAccessList(data: object): Promise<ResponseData> {
	return axios.request({
		url: 'device/access/control/list',
		data,
		method: 'POST'
	})
}

export const accessWarningLogHandle = (data: object): Promise<ResponseData> => {
	return axios.request({
		url: '/device/access/user/warning_log/handle',
		method: 'POST',
		data
	})
}

export const authExpiringList = (data: object): Promise<ResponseData> => {
	return axios.request({
		url: '/device/device/auth/expiring_list',
		method: 'POST',
		data
	})
}

export function getLockList(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/device/list',
		data,
		method: 'POST'
	})
}

export const getVacancyAlarmList = (data: any): Promise<ResponseData<IVacancyAlarmRes>> => {
	return axios.request({
		url: '/house/house_room/roomAlarmPageList',
		data,
		method: 'POST'
	})
}

export const confirmVacancyAlarm = (data: { id: string; reason: string }): Promise<ResponseData> => {
	return axios.request({
		url: '/house/house_room/roomAlarmAudit',
		data,
		method: 'POST'
	})
}

type T_AUTH_OPERATION_LIST = {
	like?: string
	address?: string
	[key: string]: unknown
}
/** 授权操作记录列表 */
export function getAuthOperationList(data: T_AUTH_OPERATION_LIST): Promise<ResponseData> {
	return axios.request({
		url: '/device/device/authOperation/list',
		data,
		method: 'POST'
	})
}
/**
 * 分页查询能耗费读数
 * @param data
 * @returns
 */
export const deviceEnergyWarning = (data: any): Promise<ResponseData<IVacancyAlarmRes>> => {
	return axios.request({
		url: '/device/deviceEnergyWarning/page',
		data,
		method: 'POST'
	})
}

/**
 * 自动补抄
 * @param data
 * @returns
 */
export const repairReadRecord = (): Promise<ResponseData<IVacancyAlarmRes>> => {
	return axios.request({
		url: '/device/meter_read_record/auto/repair_read_record',
		method: 'GET'
	})
}

/** 根据ID删除授权操作记录 */
export function deleteAuthOperation(id: string): Promise<ResponseData> {
	return axios.request({
		url: `/device/device/authOperation/remove/${id}`,
		method: 'POST'
	})
}

/** 失败授权重新下发 */
export function retryAuthOperation(id: string): Promise<ResponseData> {
	return axios.request({
		url: `/device/device/authOperation/retry/${id}`,
		method: 'POST'
	})
}

export function grantTenantAccessAuth(data: object): Promise<ResponseData> {
	return axios.request({
		url: 'contract/contract/grant_tenant_access_auth',
		method: 'POST',
		data
	})
}

// 批量查询包租合同通行授权情况
export function getBatchDeviceAuth(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/contract/renter_contract/device/detail/enter',
		method: 'POST',
		data
	})
}

// 批量下发包租合同授权
export function batchSendDeviceAuth(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/contract/renter_device_info/save/batch/device/enter',
		method: 'POST',
		data
	})
}

export function getDeviceList(params: object): Promise<ResponseData> {
	return axios.request({
		url: '/saas-rental-device/device/device/list',
		params,
		method: 'GET'
	})
}

export function getDeviceCounts(params: object): Promise<ResponseData> {
	return axios.request({
		url: '/saas-rental-device/device/device/count_status',
		params,
		method: 'GET'
	})
}

export function getPlatformList(data: any): Promise<ResponseData> {
	return axios.request({
		url: 'saas-rental-device/device/platform/list',
		data: data,
		method: 'GET'
	})
}

export function searchByAddress(data: any): Promise<ResponseData> {
	return axios.request({
		url: 'basesearch/house/search_by_address',
		data: data,
		method: 'post'
	})
}

export function getPropertyList(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/saas-rental-property/property/property/list',
		data,
		method: 'POST'
	})
}

export function getPropertyDevice(params: object): Promise<ResponseData> {
	return axios.request({
		url: '/saas-rental-device/device/device/list_property_device_group',
		params,
		method: 'GET'
	})
}

export function getUnbindDevices(params: any): Promise<ResponseData> {
	return axios.request({
		url: 'saas-rental-device/device/device/unbind/devices',
		params,
		method: 'GET'
	})
}

export function getCommunities(data: any): Promise<ResponseData> {
	return axios.request({
		url: 'basesearch/house/communitys',
		data: data,
		method: 'post'
	})
}

export function getBuildingList(communityId: string): Promise<ResponseData> {
	return axios.request({
		url: '/house/house/list_building',
		method: 'GET',
		params: {
			communityId
		}
	})
}

export function syncPlatformDevices(platformId: string, bigType: number): Promise<ResponseData> {
	return axios.request({
		url: `device/device/sync_devices/${platformId}/${bigType}`,
		method: 'post'
	})
}

export function syncPlatformDevicesAll(platformId: string): Promise<ResponseData> {
	return axios.request({
		url: `saas-rental-device/device/device/sync_devices/${platformId}`,
		method: 'post'
	})
}

export function getDeviceOrigin(params: object): Promise<ResponseData> {
	return axios.request({
		url: '/saas-rental-device/device/device/get',
		params,
		method: 'GET'
	})
}

/**
 * 充电记录
 * @param data
 */
export function chargePageList(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/finance/charge/pageList',
		data,
		method: 'POST'
	})
}

/**
 * 电表详情
 * @param params
 */
export function getEleMeterInfo(params: object): Promise<ResponseData> {
	return axios.request({
		url: '/saas-rental-device/device/device/get_ele_meter_info',
		params,
		method: 'GET'
	})
}

/**
 * 解绑电表
 * @param id
 */
export function unbindDevice(id: string): Promise<ResponseData> {
	return axios.request({
		url: `/saas-rental-device/device/device/unbind/${id}`,
		method: 'DELETE'
	})
}

/**
 * 电表通电
 * @param data
 */
export function eleMeterSwitchOn(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/saas-rental-device/device/device/eleMeterSwitchOn',
		data,
		method: 'POST'
	})
}

/**
 * 电表断电
 * @param data
 */
export function eleMeterSwitchOff(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/device/eleMeterSwitchOff',
		data,
		method: 'POST'
	})
}

/**
 * 电表强制断电
 * @param data
 */
export function eleMeterForceOpen(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/device/eleMeterForceOpen',
		data,
		method: 'POST'
	})
}

/**
 * 电表重置度数
 * @param data
 */
export function eleMeterResetByCollector(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/device/eleMeterResetByCollector',
		data,
		method: 'POST'
	})
}

/**
 * 获取设备详情
 * @param params
 */
export function getDeviceDetail(params: object): Promise<ResponseData> {
	return axios.request({
		url: '/saas-rental-device/device/device/get',
		params,
		method: 'GET'
	})
}

/**
 * 电费充值
 * @param data
 */
export function chargeDevice(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/finance/charge/device',
		data,
		method: 'POST'
	})
}

/**
 *  水表详情
 * @param params
 */
export function getWaterMeterInfo(params: object): Promise<ResponseData> {
	return axios.request({
		url: '/saas-rental-device/device/device/get_water_meter_info',
		params,
		method: 'GET'
	})
}

/**
 *  用水记录
 * @param data
 */
export function waterMeterFetchAmountHistoryWithFees(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/device/waterMeterFetchAmountHistoryWithFees',
		data,
		method: 'POST'
	})
}

/**
 *  水费清零
 * @param data
 */
export function waterMeterChargeReset(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/device/waterMeterChargeReset',
		data,
		method: 'POST'
	})
}

// 获取电表抄表记录
export const getEleMeterReadRecord = (data): Promise<ResponseData> => {
	return axios.request({
		url: '/device/meter_read_record/ele/page',
		method: 'POST',
		data
	})
}

// 获取水表抄表记录
export const getWaterMeterReadRecord = (data): Promise<ResponseData> => {
	return axios.request({
		url: '/device/meter_read_record/water/page',
		method: 'POST',
		data
	})
}

/**
 * 充值记录 能耗费充值
 * @param data
 */
export const chargeRecord = (data: object): Promise<ResponseData> => {
	return axios.request({
		url: '/finance/charge/pageList',
		data,
		method: 'POST'
	})
}

/**
 * 设备充值
 * @param data
 */
export const deviceRecharge = (data: object): Promise<ResponseData> => {
	return axios.request({
		url: '/finance/charge/device',
		data,
		method: 'POST'
	})
}

export const getDeviceStatus = (data: {deptId?: string; empId?: string}): Promise<ResponseData> => {
	return axios.request({
		url: '/admin/house/workbench/device_stats',
		data,
		method: 'POST'
	})
}

/**
 * 能耗费设备列表
 * @param data
 */
export const energyList = (data: object): Promise<ResponseData> => {
	return axios.request({
		url: '/device/meter_read_record/energy_pay/list',
		data,
		method: 'POST'
	})
}

/**
 * 水电费月总量
 * @param data
 */
export const amountStatisticCollect = (data: object): Promise<ResponseData> => {
	return axios.request({
		url: '/device/energy/amountStatisticCollect',
		data,
		method: 'POST'
	})
}

/**
 * 根据房源ID获取设备预警详情
 * @param data
 */
export const queryRoomPlan = (data: string, methods?: number): Promise<ResponseData> => {
	return axios.request({
		url: `/device/energy_cost_room_setting/detail/${methods}/${data}`,
		method: 'GET'
	})
}

/**
 * 根据房源id查询能耗
 * @param data
 * @returns
 */
export const deviceEnergyWarningByHouse = (data: string): Promise<ResponseData> => {
	return axios.request({
		url: `/device/deviceEnergyWarning/has_data/${data}`,
		method: 'GET'
	})
}

/**
 * 获取预警详情
 * @param data
 * @returns
 */
export const getEnergyWatningList = (data: object): Promise<ResponseData> => {
	return axios.request({
		url: '/device/deviceEnergyWarning/list',
		data,
		method: 'GET'
	})
}

/**
 * 保存读数接口
 * @param data
 * @returns
 */
export const manualRepairReadRecord = (data: any): Promise<ResponseData> => {
	return axios.request({
		url: '/device/meter_read_record/manual/repair_read_record',
		data,
		method: 'POST'
	})
}

/**
 * 根据房源ID获取设备预警24小时详情
 * @param data
 */
export const meterReadRecordLastRecord = (data: any): Promise<ResponseData> => {
	return axios.request({
		url: '/device/meter_read_record/last_record',
		data,
		method: 'POST'
	})
}

/**
 * 读数详情
 * @param data
 */
export const getReadingRecord = (data: any): Promise<ResponseData> => {
	return axios.request({
		url: '/device/meter_read_record/amount_detail',
		data,
		method: 'POST'
	})
}

export const getProjectList = (params: Object): Promise<ResponseData> => {
	return axios.request({
		url: '/saas-rental-property/property/project/list',
		params,
		method: 'GET'
	})
}

